package com.cn.wanxi.servlet.product;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.ProductService;
import com.cn.wanxi.service.impl.ProductServiceImpl;
import com.cn.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/product/delete")
public class ProductDeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//     1.乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        2.得到前端的数据
       String id=req.getParameter("id");
//        3.封装数据
        ProductModel productModel = new ProductModel();
       productModel.setId(Tool.stringToInt(id));
//        4.调用服务逻辑层
        ProductService productService=new ProductServiceImpl();
//        5.得到统一格式的结果
        ResultModel resultModel=productService.delete(productModel);
//        6.将结果返回页面
        resp.getWriter().println(JSONObject.toJSONString(resultModel));


    }
}
